package com.maxd.respository.article;

import com.maxd.model.ArticleBrowsingHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

public interface ArticleBrowsingHistoryRepository extends Repository<ArticleBrowsingHistory, Long> {

    @Query(value = "select id from article_browsing_history where article_id=:articleId and user_id=:userId ",nativeQuery = true)
    Long selectCount(@Param("articleId") Long articleId, @Param("userId") Long userId);


    @Query(value = "select * from article_browsing_history where user_id=:userId",
    countQuery = "select count(*) from article_browsing_history where user_id=:userId",
    nativeQuery = true)
    Page<ArticleBrowsingHistory> selectArticleBrowsingHistoryList(@Param("userId") Long userId, Pageable pageable);

    @Transactional
    @Modifying
    @Query(value = "update article_browsing_history set create_time=:createTime where id=:Id",nativeQuery = true)
    Integer updateCreateTimeById(@Param("Id") Long Id, @Param("createTime") Date createTime);


}